package com.chrudgames.juicedietrecipes;


import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

public class details extends Activity {
	
public String lookupKey;
	
	 @Override
	 public boolean onCreateOptionsMenu(Menu menu){
		 MenuInflater inflater = getMenuInflater();
		 inflater.inflate(R.menu.options, menu);
		 return true;
	 }
	 
	 @Override
	 public boolean onOptionsItemSelected(MenuItem item){
		 switch (item.getItemId()){
		 
        case R.id.search:
       	 Intent i3 = new Intent(this, Search.class);
       	 	startActivity(i3);
       	 return true;
		 
		 case R.id.generald:
	    		Intent i = new Intent(this, General.class);
	          	startActivity(i);
			 return true;
			 
        case R.id.help:
        	Intent i2 = new Intent(this, Help.class);
           	startActivity(i2);
            return true;
            
			 default:
				 return super.onOptionsItemSelected(item);
		 }
	 }
	 

	/** Called when the activity is first created. */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.details);

        
        /*View generalButton = findViewById(R.id.general);
        generalButton.setOnClickListener(this);*/

        

    } 
    @Override
    public void onResume()
    {
        
        Bundle b = getIntent().getExtras();
        lookupKey = b.getString("lookupKey").toString();
        
        DatabaseHandler db = new DatabaseHandler(this);
        
        
        Cursor c = db.getRecipeCursor(lookupKey);
        c.moveToFirst();
        
        final TextView mTextView = (TextView) findViewById(R.id.drink);
        mTextView.setText(c.getString(1));
        
        final TextView mTextView2 = (TextView) findViewById(R.id.description);
        mTextView2.setText(c.getString(3));
        
        final TextView mTextView3 = (TextView) findViewById(R.id.ingredients);
        mTextView3.setText(c.getString(4));
        
        final TextView mTextView4 = (TextView) findViewById(R.id.nutrition);
        mTextView4.setText(c.getString(5));
        
        final ImageView mImageViewOn = (ImageView) findViewById(R.id.favonbig);
        final ImageView mImageViewOff = (ImageView) findViewById(R.id.favoffbig);
        
        if(c.getString(6).contentEquals("0")){
        	mImageViewOn.setVisibility(View.GONE);
        	mImageViewOff.setVisibility(View.VISIBLE);
        }else{
        	mImageViewOff.setVisibility(View.GONE);
        	mImageViewOn.setVisibility(View.VISIBLE);
        }
        
    	c.close();
    	db.close();
        
    	   super.onResume();
    }
    public void onClick(View v) {

    	
        final ImageView mImageViewOn = (ImageView) findViewById(R.id.favonbig);
        final ImageView mImageViewOff = (ImageView) findViewById(R.id.favoffbig);

    	
    	DatabaseHandler db = new DatabaseHandler(this);   
    	
    	switch (v.getId()) {
    	
    	case R.id.favoffbig:
    	

    		
    		db.runQuery("update Info set favorite = '1' where _id = '" + lookupKey.toString() + "'");
    		
    		mImageViewOff.setVisibility(View.GONE);
        	mImageViewOn.setVisibility(View.VISIBLE);

          	break;
    	
    	
    	case R.id.favonbig:	

    	
    		db.runQuery("update Info set favorite = '0' where _id = '" + lookupKey.toString() + "'");

    		mImageViewOn.setVisibility(View.GONE);
        	mImageViewOff.setVisibility(View.VISIBLE);
    		
          	break;
    	}

	    	   db.close();
	          
          
        }

    
}
